<template>
	<view class="content">
		<view class="section-0">
			<view class="section-body">
				<view class="form">
					<view class="form-item">
						<view class="label">项目名称</view>
						<view class="shape"></view>
						<view class="input">
							<u--input placeholderClass="input-placeholder" class="input-body" placeholder="项目名称" v-model="project_name"></u--input>
						</view>
					</view>
					<view class="actions">
						<view class="action" @click="handleResetForm()">
							<text>重</text>
							<text>置</text>
						</view>
						<view class="action search" @click="handleSearch()">
							<text>查</text>
							<text>询</text>
						</view>
					</view>
				</view>
				<view class="list">
					<view class="problem-wrapper" v-if="list.length<=0">
						<image src="https://www.mescroll.com/img/mescroll-empty.png"></image>
						<view class="">~ 空空如也 ~</view>
					</view>
					<view :class="`item ${expandList.indexOf(index) !== -1 ? 'item__expand' : ''}`" v-for="(item, index) in list" :key="index">
					<!-- <view class="item" v-for="(item, index) in list" :key="index"> -->
						<view class="parent" @click="expandChange(index,item.main_id)">
							<view class="action" >
								<view class="iconfont icon-xiangyou1"></view>
							</view>
							<view class="name">{{ item.project_main_name }}</view>
							<view class="total">
								{{item.total}}个
							</view>
						</view>
						
						<view class="child" v-if="expandList.indexOf(index) !== -1">
							<view class="child-item" v-for="(item2, idx) in item.children" :key="idx">
								<view class="top" @click="go(item2)">
									<view class="name">
										<view class="count">
											<view class="title">{{ item2.project_name }}</view>
											<view class="total">
												{{item2.total}}
											</view>
										</view>
									</view>
									<view class="action">
										<view class="iconfont icon-xiangyou1"></view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { projectTeamIndex,projectTeamChildren } from '@/api/statistics.js'
export default {
	data() {
		return {
			list: [],
			project_name:'',
			expandList: []
		}
	},
	methods: {
		go(item) {
			uni.navigateTo({
				url: '/pages/work/manager/construction/safety/teamManagement/index?id=' + item.id + '&project_name=' + item.project_name
			})
		},
		async expandChange(id,main_id) {
			projectTeamChildren({project_id:main_id}).then(res=>{
				console.log(res.data.data);
				this.list.map(item=>{
					if(item.main_id==main_id){
						item.children=res.data.data
					}
				})
				const idx = this.expandList.indexOf(id)
				if (idx !== -1) {
					this.expandList.splice(idx, 1)
				} else {
					this.expandList.push(id)
				}
			})
		},
		//  重置
		handleResetForm() {
			this.project_name=''
			this.upCallback()
		
		},
		// 查询
		handleSearch() {
			this.upCallback()
		},
	 
	 // 查询单位
	 upCallback(){
		 projectTeamIndex({project_name:this.project_name}).then(res=>{
			 this.list=res.data.data
		 })
	 },
	},
	created() {
		this.upCallback()
	}
}
</script>
<style lang="scss" scoped>
.section-0 {
	width: 100%;
	background: #2e5efe;
	.section-body {
		width: 100%;
		height: 100%;
		background-color: #fff;
		overflow: hidden;
		border-top-left-radius: 60rpx;
		border-top-right-radius: 60rpx;
		.form {
			width: 100%;
			padding: 0 75rpx;
			padding-top: 40rpx;
			box-sizing: border-box;
			.form-time {
				width: 600rpx;
				min-height: 48rpx;
				margin: 0 auto;
				margin-bottom: 9rpx;
				@include clear;
				.label {
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}
				.wrapper {
					float: left;
					width: calc(100% - 134rpx);
					line-height: 48rpx;
					.item {
						float: left;
						display: inline-block;
						height: 48rpx;
						border-radius: 35rpx;
						padding: 0 16rpx;
						text-align: center;
						font-size: 26rpx;
						line-height: 44rpx;
						margin-left: 10rpx;
						transition: 0.3s ease;
						margin-bottom: 16rpx;
						box-sizing: border-box;
						border: 1rpx solid #395cf5;
						background-color: #fff;
						color: #395cf5;
					}
					.item__active {
						background-color: #395cf5;
						color: #fff;
					}
				}
			}
			.form-item {
				width: 600rpx;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				margin: 0 auto;
				margin-bottom: 25rpx;
				&:last-child {
					margin-bottom: 34rpx;
				}
				@include clear();
				.label {
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}
				.shape {
					width: 3rpx;
					height: 32rpx;
					background-color: #7f98ae;
					float: left;
					margin-top: 8rpx;
				}
				.input {
					float: left;
					width: calc(100% - 134rpx - 3rpx);
					.input-body {
						box-sizing: border-box;
						width: 100%;
						height: 44rpx;
						padding: 0 !important;
						border: none;
						padding-left: 30rpx !important;
						padding-right: 30rpx !important;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0, 0, 0, 0.7);
					}
					.input-placeholder {
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0, 0, 0, 0.5);
					}
				}
			}
			.actions {
				width: 100%;
				height: 50rpx;
				margin-top: 29rpx;
				padding-bottom: 40rpx;
				display: flex;
				justify-content: space-between;
				.action {
					width: 288rpx;
					height: 48rpx;
					background-color: #395cf5;
					border-radius: 20rpx;
					text-align: center;
					line-height: 48rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					line-height: 48rpx;
					color: #ffffff;
					text {
						&:first-child {
							margin-right: 20rpx;
						}
					}
				}
				.search {
					background-color: #1534ce;
				}
			}
		}

		.list {
			width: 670rpx;
			box-sizing: border-box;
			margin-left: 40rpx;
			border-top: 2rpx solid #d8e4f2;
			.problem-wrapper {
						color: #808080;
						margin: 0 auto;
						text-align: center;
						image {
							margin-top: 300rpx;
							width: 200rpx;
							height: 200rpx;
						}
					}
			.item {
				width: 100%;
				border-bottom: solid 2rpx #f2f2f0;
				.parent {
					width: 100%;
					display: flex;
					@include clear();
					.name {
						width: 500rpx;
						line-height: 30rpx;
						padding: 26rpx 0;
						font-size: 30rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 2rpx;
						color: #3b3c40;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}
					.total{
						min-width: 30px;
						    height: 30px;
						margin-left: 15rpx;
						margin-top: 10rpx;
						background-color: #FFDE00;
						color: #395CCE;
						border-radius: 50%;
						text-align: center;
						font-weight: bold;
						line-height: 30px;
						font-size: 12px;
					}
					.action {
						float: left;
						width: 32rpx;
						margin-right: 18rpx;
						line-height: 82rpx;
						text-align: center;
						color: #3b3c40;
						.iconfont {
							font-size: 32rpx;
							transition: 0.2s ease;
							transform: rotate(90deg);
						}
					}
				}
				.score {
					height: 50rpx;
					font-size: 26rpx;
					display: flex;
					margin-left: 50rpx;
					.quantity {
						margin-right: 30rpx;
						text {
							font-size: 30rpx;
							color: #1534ce;
							font-weight: bold;
						}
					}
				}
				.child {
					width: 750rpx;
					margin-left: -40rpx;
					background: #f2f2fa;
					.child-item {
						width: 100%;
						border-bottom: 2rpx solid #e3e8f5;
						@include clear();
						&:last-child {
							border-bottom: none;
						}

						.top {
							width: 100%;
							overflow: hidden;
							box-sizing: border-box;
							padding-left: 100rpx;
							// padding-right: 40rpx;
							display: flex;
							.name {
								width: calc(100% - 70rpx);
								box-sizing: border-box;
								padding-top: 20rpx;
								padding-bottom: 10rpx;
								font-size: 26rpx;
								color: #3b3c40;
								font-size: 30rpx;
								.count {
								font-weight: bold;
								display: flex;
									.title{
										width: 480rpx;
										white-space: nowrap;
										overflow: hidden;
										margin-top: 10rpx;
										text-overflow: ellipsis;
										font-weight: normal;
									}
									.total{
										min-width: 30px;
										    height: 30px;
										margin-left: 20rpx;
										background-color: #FFDE00;
										color: #395CCE;
										border-radius: 50%;
										text-align: center;
										font-weight: bold;
										line-height: 30px;
										font-size: 12px;
									}
								}
							}
							.action {
								float: right;
								width: 32rpx;
								line-height: 100rpx;
								text-align: center;
								color: #7f98ae;
								.iconfont {
									font-size: 32rpx;
								}
							}
						}
					}
				}
			}
			.item__expand {
				.parent {
					.action {
						.iconfont {
							transform: rotate(-90deg);
						}
					}
				}
				.child {
					box-shadow: 0rpx 10rpx 10rpx 0rpx rgba(0, 0, 0, 0.05) inset;
				}
			}
		}
	}
}
</style>
